﻿package hapi.event;

class HapiDispatcher<EventType> implements Dispatcher<EventType>, implements Notifier<EventType> {
    
    private var listeners : List<Listener<EventType>>;
 
    public function new() {
        listeners = new List();
    }
	
    public function notify( l ) {
        listeners.push(l);
    }
 
    public function stopNotifying( l ) {
        return listeners.remove(l);
    }
 
    public function call(f:EventType->Void) {
       var l:Listener<EventType> = { handleEvent : f };
       listeners.push(l);
       return l;
    }
 
    public function dispatchEvent(e) {
		for( l in listeners )
		   l.handleEvent(e);
    }
}